﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using CF_DAL_WS.Models;

namespace CF_DAL_WS.DTO
{
    public class ContactDTO
    {
        public int ID { get; set; }
        public string Email { get; set; }
        public string Name { get; set; }
        public string Subject { get; set; }
        public string Detail { get; set; }
        public List<ReplyDTO> Replies { get; set; }

        public static ContactDTO Translate(Contact Entity)
        {
            if (Entity != null)
            {
                var dto = new ContactDTO
                {
                    ID = Entity.ID,
                    Name = Entity.Name,
                    Email = Entity.Email,
                    Subject = Entity.Subject,
                    Detail = Entity.Detail,
                    Replies = new List<ReplyDTO>()
                };
                if (Entity.Reply != null)
                {
                    foreach (var item in Entity.Reply)
                    {
                        dto.Replies.Add(ReplyDTO.Translate(item));
                    }
                }
                return dto;
            }
            return null;
        }

        public static ContactDTO TranslateBase(Contact Entity)
        {
            if (Entity != null)
            {
                var dto = new ContactDTO
                {
                    ID = Entity.ID,
                    Name = Entity.Name,
                    Email = Entity.Email,
                    Subject = Entity.Subject,
                    Detail = Entity.Detail
                };
                return dto;
            }
            return null;
        }

        public static Contact Reverse(ContactDTO obj)
        {
            var entity = new Contact
            {
                Name = obj.Name,
                Email = obj.Email,
                Subject = obj.Subject,
                Detail = obj.Detail
            };
            return entity;
        }

        public void UpdateEntity(ref Contact entity)
        {
            entity.Name = Name;
            entity.Email = Email;
            entity.Subject = Subject;
            entity.Detail = Detail;
        }
    }
}